package com.franklin.ideaplugin.api.beans.declaration;

import com.franklin.ideaplugin.api.beans.variable.IVariable;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiExpression;
import com.intellij.psi.PsiType;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * map声明语句
 *
 * @author Ye Junhui
 * @since 2024/3/6
 */
public interface IDeclaration {

    /**
     * 获取map变量
     * @return
     */
    @Nullable
    IVariable getVariable();

    /**
     * 获取map创建语句
     * @return
     */
    default  <T extends PsiExpression> T getCreateExpression(Class<T> expressionType){
        PsiElement psiElement = getVariable().getPsiElement();
        return PsiTreeUtil.findChildOfType(psiElement,expressionType);
    }

    /**
     * 获取工程
     * @return
     */
    default Project getProject(){
        return getVariable().getPsiElement().getProject();
    }

    /**
     * 获取语句psi元素
     *
     * @return
     */
    @NotNull
    PsiElement getPsiElement();

    /**
     * 获取类型
     * @return
     */
    PsiType getPsiType();
}
